home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 14642 / 14642.xpi / chrome / modules / trackers / video.js < prev    next >
Text File  |  2009-10-19  |  3KB  |  69 lines

  1. /* Copyright 2009, Boomtango.com.  All Rights Reserved. */
  2. /* video.js
  3.  * Responsible for tracking video files
  4.  */
  5.  
  6. var EXPORTED_SYMBOLS = ["video"];
  7.  
  8. var video = {
  9.     name: "Video",
  10.     name_plural: "Videos",
  11.     color: "#1a9dbd",
  12.     isInternal: true,
  13.     preview: function(doc, node, data){
  14.         if(data.preview){
  15.             var iframe = doc.createElement(
  16.                 "iframe"
  17.             );
  18.             var txt = '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/' + data.preview + '&hl=en&fs=1&color1=0x006699&color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + data.preview + '&hl=en&fs=1&color1=0x006699&color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>';
  19.             iframe.setAttribute("src", 
  20.                     "data:text/html," + encodeURI(txt));
  21.             iframe.setAttribute("width", "352");
  22.             iframe.setAttribute("height", "288");
  23.             node.appendChild(iframe);
  24.         }
  25.     },
  26.     onLoadTracks: function(url, doc){
  27.         var result = [];
  28.         if(url.substr(0,this._url.length) == this._url){
  29.             result.push(
  30.                 {
  31.                     type: "video",
  32.                     preview:  this._buildSnippet(url)
  33.                 }
  34.             );
  35.         } else if(doc){
  36.             var yturl = "http://www.youtube.com";
  37.             (function(list){
  38.                 var ctr = list.length;
  39.                 while(ctr--){
  40.                     var src = list[ctr].src;
  41.                     if(src && src.substr(0, yturl.length) == yturl){
  42.                         result.push(
  43.                             {
  44.                                 type: "video",
  45.                                 preview: this._buildSnippet(src, true)
  46.                             }
  47.                         );
  48.                     }
  49.                 }
  50.             }).apply(this, [ doc.getElementsByTagName('embed')]);
  51.         }
  52.         return result;
  53.     },
  54.  
  55.     _buildSnippet: function(url, embed){
  56.         var result = /[?&]v=([^&]*)/.exec(url);
  57.         if(result && result.length > 1){
  58.             return id = result[1];
  59.         }  else if(embed){
  60.             var result = /\/v\/([^&]*)/.exec(url);
  61.             if(result && result.length > 1){
  62.                 return id = result[1];
  63.             }
  64.         }
  65.         return "";
  66.     },
  67.     _url: "http://www.youtube.com/watch?v"
  68. };
  69.